<?php

namespace app\common\model;

use think\Model;

class Adver extends Model
{

    //获取指定Id的广告详细信息
    public function get_ad($id)
    {
        $ads = $this->where('Id', $id)->find();
        return $ads;
    }
    //更改广告位信息
    public function up_ad($data)
    {
        $data['img_url'] = '/uploads/' . $data['img_url'];
        $data['img_url'] = str_replace("\\", "/", $data['img_url']);
        if ($this->allowField(true)->isUpdate(true)->save($data, ['Id' => $data['Id']])) {
            return true;
        }
        return false;
    }
    //获取广告列表数据
    public function getlist($page, $limit)
    {
        $cate_list = $this->limit($page, $limit)->select();
        $list_number = $this->count();
        $msg = '';
        if ($cate_list->isEmpty()) {
            $msg = '暂无数据';
        }
        return json_l($cate_list->toArray(), $list_number, $msg);
    }
}
